package x10.enums;

import java.util.EnumSet;
import java.util.HashMap;

/**
 *  Remote - enumeration of RF remote control codes

 *  Example: 5D 14 aa bb cc
 *
 *      5D = CM15A Prefix for RF Code
 *      14 = Header identifier for Remote control codes/commands
 *      aa = check code (see CheckCode.java)
 *      bb = Remote code (below)
 *      cc = Address (house code + 0x0)
 *
 * @author Denny
 * @date 20110126
 */
public enum Remote {   //CheckCode RemoteCode (for address = 0x00, house code M)
    UNKNOWN_00(0),     //D5 00
    DVD_ANGLE(1),      //D6 01
    POWER_STANDBY(2),  //D7 02
    LIVE_TV(3),        //D8 03
    DVD_MENU(4),       //D9 04
    PHOTOS(5),         //DA 05
    MUSIC(6),          //DB 06
    UNKNOWN_07(7),     //DC 07
    VOLUME_MINUS(8),   //DD 08
    VOLUME_PLUS(9),    //DE 09
    MUTE(10),          //DF 0A
    CHANNEL_PLUS(11),  //E0 0B
    CHANNEL_MINUS(12), //E1 0C
    BUTTON_1(13),      //E2 0D
    BUTTON_2(14),      //E3 0E
    BUTTON_3(15),      //E4 0F
    BUTTON_4(16),      //E5 10
    BUTTON_5(17),      //E6 11
    BUTTON_6(18),      //E7 12
    BUTTON_7(19),      //E8 13
    BUTTON_8(20),      //E9 14
    BUTTON_9(21),      //EA 15
    TELETEXT(22),      //EB 16
    BUTTON_0(23),      //EC 17
    RECORDED_TV(24),   //ED 18
    UNKNOWN_19(25),    //EE 19
    UP(26),            //EF 1A
    MEDIA_MENU(27),    //F0 1B
    UNKNOWN_1C(28),    //F1 1C
    LEFT(29),          //F2 1D
    OK(30),            //F3 1E
    RIGHT(31),         //F4 1F
    QUIT(32),          //F5 20
    REPLAY(33),        //F6 21
    DOWN(34),          //F7 22
    SKIP(35),          //F8 23
    REWIND(36),        //F9 24
    PLAY(37),          //FA 25
    FAST_FORWARD(38),  //FB 26
    RECORD(39),        //FC 27
    STOP(40),          //FD 28
    PAUSE(41),         //FE 29
    UNKNOWN_2A(42),    //FF 2A
    UNKNOWN_2B(43),    //00 2B
    UNKNOWN_2C(44),    //01 2C
    VIDEO(45),         //02 2D
    UNKNOWN_2E(46),    //03 2E
    INFO(47),          //04 2F
    CLEAR(48),         //05 30
    GUIDE(49),         //06 31
    RED(50),           //07 32
    GREEN(51),         //08 33
    YELLOW(52),        //09 34
    BLUE(53),          //0A 35
    ENTER(54),         //0B 36
    BUTTON_ASTERISK(55),//0C 37  //*
    BUTTON_POUND(56),  //0D 38   //#
    UNKNOWN_39(57),    //0E 39   //Large chunk of unknowns ... for consistency in the address space
    UNKNOWN_3A(58),    //0F 3A
    UNKNOWN_3B(59),    //10 3B
    UNKNOWN_3C(60),    //11 3C
    UNKNOWN_3D(61),    //12 3D
    UNKNOWN_3E(62),    //13 3E
    UNKNOWN_3F(63),    //14 3F
    UNKNOWN_40(64),    //15 40
    UNKNOWN_41(65),    //16 41
    UNKNOWN_42(66),    //17 42
    UNKNOWN_43(67),    //18 43
    UNKNOWN_44(68),    //19 44
    UNKNOWN_45(69),    //1A 45
    UNKNOWN_46(70),    //1B 46
    AUTOFOCUS(71),     //1C 47
    UNKNOWN_48(72),    //1D 48
    UNKNOWN_49(73),    //1E 49
    UNKNOWN_4A(74),    //1F 4A
    UNKNOWN_4B(75),    //20 4B
    UNKNOWN_4C(76),    //21 4C
    UNKNOWN_4D(77),    //22 4D
    UNKNOWN_4E(78),    //23 4E
    UNKNOWN_4F(79),    //24 4F
    ZOOM_IN(80),       //25 50
    ZOOM_OUT(81),      //26 51
    FOCUS_UP(82),      //27 52
    FOCUS_DOWN(83),    //28 53
    GOTO_PRESET_5(84), //29 54
    SET_PRESET_5(85),  //2A 55
    GOTO_PRESET_6(86), //2B 56
    SET_PRESET_6(87),  //2C 57
    GOTO_PRESET_7(88), //2D 58
    SET_PRESET_7(89),  //2E 59
    GOTO_PRESET_8(90), //2F 5A
    SET_PRESET_8(91),  //30 5B
    GOTO_PRESET_9(92), //31 5C
    SET_PRESET_9(93),  //32 5D
    IRIS_UP(94),       //33 5E
    IRIS_DOWN(95),     //34 5F
    PAN_LEFT(96),      //35 60
    PAN_RIGHT(97),     //36 61
    TILT_UP(98),       //37 62
    TILT_DOWN(99),     //38 63
    GOTO_PRESET_1(100),//39 64
    SET_PRESET_1(101), //3A 65
    GOTO_PRESET_2(102),//3B 66
    SET_PRESET_2(103), //3C 67
    GOTO_PRESET_3(104),//3D 68
    SET_PRESET_3(105), //3E 69
    GOTO_PRESET_4(106),//3F 6A
    SET_PRESET_4(107), //40 6B
    CENTER(108),       //41 6C
    CLEAR_ALL_POSITIONS(109),  //42 6D  //Clear all camera preset positions (1-9)
    SWEEP(110),        //43 6E
    UNKNOWN_6F(111);              
    //This is as far as I've mapped (dls) 2011-01-16
    //I'd imagine that the address space goes out to at least 127, if not 255

    //int value of the remote code
    private final int code;

    //Lookup hashmap to convert from integer to Remote code
    private static final HashMap<Integer,Remote> lookup = new HashMap<Integer,Remote>();

    //Hidden class to populate the hashmap
    static {
        for(Remote r : EnumSet.allOf(Remote.class)){
            lookup.put(r.code, r);
        }
    }

    /**
     * Constructor
     * @param code - int value of the remote code
     */
    Remote(int code){
        this.code = code;
    }

    /**
     * Utility method to get the byte value of the Remote code object
     * @return
     */
    public byte getByteValue(){
        return (byte) this.code;
    }

    /**
     * Utility method to instantiate a remote object from a remote code
     * @param remoteCode - int value of the remote code byte
     * @return - Remote object
     */
    public static Remote getRemote(int remoteCode){
        return lookup.get(remoteCode);
    }
}
